package com.ruoyi.web.controller.threeViolation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.threeViolation.dto.ViolationEducatingDto;
import com.ruoyi.threeViolation.vo.ViolationEducatingVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.threeViolation.domain.ViolationEducating;
import com.ruoyi.threeViolation.service.IViolationEducatingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 三违帮教Controller
 *
 * @author lth
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/threeViolation/educating")
public class ViolationEducatingController extends BaseController
{
    @Autowired
    private IViolationEducatingService violationEducatingService;

    /**
     * 查询三违帮教列表
     */
    @PreAuthorize("@ss.hasPermi('threeViolation:educating:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViolationEducating violationEducating)
    {
        startPage();
        List<ViolationEducating> list = violationEducatingService.selectViolationEducatingList(violationEducating);
        return getDataTable(list);
    }

    /**
     * 导出三违帮教列表
     */

    @PreAuthorize("@ss.hasPermi('threeViolation:educating:export')")
    @Log(title = "三违帮教", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ViolationEducating violationEducating)
    {
        List<ViolationEducating> list = violationEducatingService.selectViolationEducatingList(violationEducating);
        ExcelUtil<ViolationEducating> util = new ExcelUtil<ViolationEducating>(ViolationEducating.class);
        util.exportExcel(response, list, "三违帮教数据");
    }

    /**
     * 获取三违帮教详细信息
     */
    @PreAuthorize("@ss.hasPermi('threeViolation:educating:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(violationEducatingService.selectViolationEducatingById(id));
    }

    /**
     * 新增三违帮教
     */
    @PreAuthorize("@ss.hasPermi('threeViolation:educating:add')")
    @Log(title = "三违帮教", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ViolationEducating violationEducating)
    {
        return toAjax(violationEducatingService.insertViolationEducating(violationEducating));
    }

    /**
     * 修改三违帮教
     */
    @PreAuthorize("@ss.hasPermi('threeViolation:educating:edit')")
    @Log(title = "三违帮教", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ViolationEducating violationEducating)
    {
        return toAjax(violationEducatingService.updateViolationEducating(violationEducating));
    }

    /**
     * 删除三违帮教
     */
    @PreAuthorize("@ss.hasPermi('threeViolation:educating:remove')")
    @Log(title = "三违帮教", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(violationEducatingService.deleteViolationEducatingByIds(ids));
    }


    /**
     * 查询三违帮教列表
     */
    @PreAuthorize("@ss.hasPermi('threeViolation:educating:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(ViolationEducatingVo vo)
    {
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<ViolationEducatingDto> list = violationEducatingService.getList(vo);
        return getDataTable(list);
    }
}
